<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>新增专家</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
		  content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script src="./js/jquery.min.js"></script>
	<script type="text/javascript" src="./lib/layui/layui.js"
			charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>

	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
</head>
<body>
<div class="layui-fluid">
	<div class="layui-row">
		<form class="layui-form">
			<input type="hidden" name="id" id="id"/><!-- 很重要，因为修改时要根据id进行操作  -->
			<div class="layui-form-item">
				<label for="professorName" class="layui-form-label"> <span
						class="x-red">*</span>专家姓名
				</label>
				<div class="layui-input-inline">
					<input type="text" id="professorName" name="professorName" lay-verify="professorName"
						   required="required" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-form-mid layui-word-aux">
					<span class="x-red">*</span>
				</div>
			</div>
			<div class="layui-form-item">
				<label for="gender" class="layui-form-label">
					性别
				</label>
				<div class="layui-input-inline" style="margin-top: 8px;">
					<input type="checkbox" id="gender" name="gender" lay-skin = "switch" lay-text = "男|女"  lay-filter = "gender" class="layui-input" />
				</div>
			</div>
			<div class="layui-form-item">
				<label for="birthday" class="layui-form-label">
					出生年月
				</label>
				<div class="layui-input-inline">
					<input  id="birthday" name="birthday"
							lay-verify="birthday" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label for="identityNumber" class="layui-form-label">
					身份证号
				</label>
				<div class="layui-input-inline">
					<input type="text" id="identityNumber" name="identityNumber"
						   lay-verify="identityNumber" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="workStatus" class="layui-form-label">
					工作状态
				</label>
				<div class="layui-input-inline">
					<select name="workStatus" id="workStatus">

					</select>

				</div>
			</div>
			<div class="layui-form-item">
				<label for="institution" class="layui-form-label">
					毕业院校
				</label>
				<div class="layui-input-inline">
					<input type="text" id="institution" name="institution"
						   lay-verify="institution" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="education" class="layui-form-label">
					学历
				</label>
				<div class="layui-input-inline">
					<select name="education" id="education">

					</select>

				</div>
			</div>
			<div class="layui-form-item">
				<label for="major" class="layui-form-label">
					专业
				</label>
				<div class="layui-input-inline">
					<input type="text" id="major" name="major"
						   lay-verify="major" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="employCompany" class="layui-form-label">
					工作单位
				</label>
				<div class="layui-input-inline">
					<input type="text" id="employCompany" name="employCompany"
						   lay-verify="employCompany" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label for="administrative" class="layui-form-label">
					行政职务
				</label>
				<div class="layui-input-inline">
					<select type="text" id="administrative" name="administrative"
							lay-verify="administrative" autocomplete="off" class="layui-input">
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label for="technicalPost" class="layui-form-label">
					行政职务
				</label>
				<div class="layui-input-inline">
					<select type="text" id="technicalPost" name="technicalPost"
							lay-verify="technicalPost" autocomplete="off" class="layui-input">
					</select>
				</div>
			</div>
					<div class="layui-form-item">
						<label for="phone" class="layui-form-label">
							固定电话
						</label>
						<div class="layui-input-inline">
							<input type="phone" id="phone" name="phone"
								   lay-verify="telephone" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label for="mobliePhone" class="layui-form-label">
							手机号
						</label>
						<div class="layui-input-inline">
							<input type="text" id="mobliePhone" name="mobliePhone"
								   lay-verify="mobliePhone" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label for="address" class="layui-form-label">
							所在地址
						</label>
						<div class="layui-input-inline">
							<input type="text" id="address" name="address" placeholder="可以通过下方的选择或者直接输入"
								   lay-verify="address" autocomplete="off" class="layui-input">
						</div>
						<!-- start-->
						<div class="layui-form-item x-city" id="end">
							<!--<label class="layui-form-label">所在地址</label>-->
							<div class="layui-input-inline">
								<select name="province" id="province" lay-filter="province">
									<option value="">请选择省</option>
								</select>
							</div>
							<div class="layui-input-inline">
								<select name="city" id="city" lay-filter="city">
									<option value="">请选择市</option>
								</select>
							</div>
							<div class="layui-input-inline">
								<select name="area" id="area" lay-filter="area">
									<option value="">请选择县/区</option>
								</select>
							</div>
						</div>

						<!-- end -->
					</div>
					<div class="layui-form-item">
                  <label for="projectCategory" class="layui-form-label"> <span
                          class="x-red"></span>评审项目类型
                  </label>
                  <div class="layui-input-inline">
                      <input type="text" id="projectCategory" name="projectCategory"
                             lay-verify="projectCategory" autocomplete="off"
                             class="layui-input" required="">
                  </div>
              </div>
              <div class="layui-form-item">
                  <label for="workDate" class="layui-form-label"> <span
                          class="x-red"></span>专家工作的年限
                  </label>
                  <div class="layui-input-inline">
                      <input type="number" id="workDate" name="workDate"
                             lay-verify="workDate" autocomplete="off" class="layui-input" value="0"  min="0" step="1" required="">
                  </div>
              </div>
              <div class="layui-form-item">
                  <label for="createBy" class="layui-form-label"> <span
                          class="x-red"></span>创建者
                  </label>
                  <div class="layui-input-inline">
                      <input type="text" id="createBy" name="createBy"
                             lay-verify="createBy" autocomplete="off"
                             class="layui-input" required="">
                  </div>
              </div>

				<div class="layui-form-item">
					<label class="layui-form-label"></label> <label
						class="layui-form-label"></label>
					<button class="layui-btn" lay-filter="update" lay-submit="">更新</button>
				</div>
			</form>
		</div>
	</div>
<script type="text/javascript" src="./js/xcity.js"></script>
<script>layui.use([ 'form', 'laydate','layer', 'jquery','code'],
		function() {
			var $ = layui.jquery;
			form = layui.form;
			var layer = layui.layer;
			var laydate=layui.laydate;

			//生日
			laydate.render({
				elem : '#birthday' //指定元素
				,trigger: 'click'
			});
			//工作状态
			var $role=$("#workStatus");
			$.get("js/param.json",function(data){
				$.each(data.workStatus,function(i,d){
					$role.append(new Option(d,d));
				});
				form.render();//重绘表单
			});
			//学历
			var $role1=$("#education");
			$.get("js/param.json",function(data){
				$.each(data.education,function(i,d){
					$role1.append(new Option(d,d));
				});
				form.render();//重绘表单
			});
			//技术职称
			var $role2=$("#technicalPost");
			$.get("js/param.json",function(data){
				$.each(data.technicalPost,function(i,d){
					$role2.append(new Option(d,d));
				});
				form.render();//重绘表单
			});
			//行政职务
			var $role3=$("#administrative");
			$.get("js/param.json",function(data){
				$.each(data.administrative,function(i,d){
					$role3.append(new Option(d,d));
				});
				form.render();//重绘表单
			});
			//获得当前id信息
				var id=location.search.substring(1);
				//alert(id+">>>>>>>");
				$.getJSON("professorGet",{id:id},function(obj){
				    alert(JSON.stringify(obj))
					for (var i in obj) {
						$("#" + i).val(obj[i]);
					}
                    if (obj.gender == "男") {
                        $("#gender").attr("checked", "checked")
                    }
                    var addr= obj.address.split("-");
                    $('#end').xcity(addr[0],addr[1],addr[2]);
					//role单独处理
					//$role.val(obj.role);
					//alert("obj role:"+obj.role);
					form.render();//重绘表单
				});
				//自定义验证规则
			/*	form.verify({
					name : function(value) {
						if (value.length < 2||value.length >12) {
							return '用户名必须是2-12个字符';
						}
					}
				});*/

            function initAddr(){

                var p=$("#province").val();
                var c=$("#city").val();
                var area=$("#area").val();
                $("#address").val(p+" "+c+" "+area);
                form.render();
            }

				//监听提交
				form.on('submit(update)',
					function(data) {
                            if ( $("#gender").is(':checked')) {
                                data.field.gender = "男";
                            } else {
                                data.field.gender = "女";
                            }


                            //initAddr();
                        var p=$("#province").val();
                        var c=$("#city").val();
                        var area=$("#area").val();
                        data.field.address=p+" "+c+" "+area;
						//修改人为登录人
						/*$("#modifyBy").val(USER.userName)
						data.field.modifyBy=USER.userName;*/

						//发异步，把数据提交给
						$.post("professorUpdate",data.field,function(r){
							if(r>0){
								parent.layer.alert("修改成功", {
									icon : 6
								},function(index,item){
									xadmin.close(); 
									// 可以对父窗口进行刷新 
									xadmin.father_reload();
								});

							}else{
								parent.layer.alert("修改失败，请核对", {
									icon : 1
								});
							}
						});
						 
						return false;
					});
	
			});
	</script>

</body>

</html>